package com.edyd.customer.api.config;

import com.edyd.customer.api.interceptor.ClientAuthInterceptor;
import com.edyd.customer.api.interceptor.SessionInterceptor;
import com.fow.core.platform.web.filter.PlatformFilter;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by Greg.Chen on 2015/5/27.
 */
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {

    @Bean
    public FilterRegistrationBean filterRegistrationBean () {

        PlatformFilter platformFilter = new PlatformFilter();

        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(platformFilter);
        registrationBean.addUrlPatterns("/*");
        return registrationBean;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry){

        registry.addInterceptor(clientAuthInterceptorBean())
                .addPathPatterns("/**")
                .excludePathPatterns("/");

        registry.addInterceptor(sessionInterceptorBean())
                .addPathPatterns("/**")
                .excludePathPatterns("/");
    }


    @Bean
    public SessionInterceptor sessionInterceptorBean() {

        return new SessionInterceptor();
    }

    @Bean
    public ClientAuthInterceptor clientAuthInterceptorBean() {

        return new ClientAuthInterceptor();
    }


/*
    @Bean
    public CommonsMultipartResolver multipartResolver(){
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
        resolver.setDefaultEncoding("utf-8");
        resolver.setMaxUploadSize(52428800000L);
        resolver.setMaxInMemorySize(40960);

        return resolver;
    }*/

}
